package com.xbts.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.enums.BusinessType;
import com.xbts.system.domain.CnSettingHomePic;
import com.xbts.system.service.ICnSettingHomePicService;
import com.xbts.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 首页轮播图列Controller
 * @author xbts
 * @date 2023-09-05
 */
@Api("首页轮播图列")
@RestController
@RequestMapping("/system/home/pic")
public class CnSettingHomePicController extends BaseController {

    @Autowired
    private ICnSettingHomePicService cnSettingHomePicService;

    /**
     * 查询首页轮播图列表
     */
    @ApiOperation("查询首页轮播图列表")
    @GetMapping("/list")
    public AjaxResult list() {
        return success(cnSettingHomePicService.selectCnSettingHomePicList());
    }

    /**
     * 导出首页轮播图列表
     */
    @ApiOperation("导出首页轮播图列表")
    @PreAuthorize("@ss.hasPermi('system:pic:export')")
    @Log(title = "首页轮播图列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody CnSettingHomePic cnSettingHomePic) {
        List<CnSettingHomePic> list = cnSettingHomePicService.selectCnSettingHomePicList();
        ExcelUtil<CnSettingHomePic> util = new ExcelUtil<CnSettingHomePic>(CnSettingHomePic.class);
        util.exportExcel(response, list, "首页轮播图列数据");
    }

    /**
     * 获取首页轮播图列详细信息
     */
    @ApiOperation("获取首页轮播图列详细信息")
    @ApiImplicitParam(name = "id", value = "首页轮播图列ID", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:pic:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(cnSettingHomePicService.selectCnSettingHomePicById(id));
    }

    /**
     * 新增首页轮播图列
     */
    @ApiOperation("新增首页轮播图列")
    @PreAuthorize("@ss.hasPermi('system:pic:add')")
    @Log(title = "首页轮播图列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CnSettingHomePic cnSettingHomePic) {
        return toAjax(cnSettingHomePicService.insertCnSettingHomePic(cnSettingHomePic));
    }

    /**
     * 修改首页轮播图列
     */
    @ApiOperation("修改首页轮播图列")
    @PreAuthorize("@ss.hasPermi('system:pic:edit')")
    @Log(title = "首页轮播图列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CnSettingHomePic cnSettingHomePic) {
        return toAjax(cnSettingHomePicService.updateCnSettingHomePic(cnSettingHomePic));
    }

    /**
     * 删除首页轮播图列
     */
    @ApiOperation("删除首页轮播图列")
    @ApiImplicitParam(name = "ids", value = "首页轮播图列ID集合", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:pic:remove')")
    @Log(title = "首页轮播图列", businessType = BusinessType.DELETE)
	@PostMapping("/batchDelete")
    public AjaxResult batchDelete(@RequestBody List<String> ids) {
        return toAjax(cnSettingHomePicService.deleteCnSettingHomePicByIds(ids));
    }
}
